﻿(function () {
    var closeCallBack;

    // 关闭窗口
    window.closeWindow = function closeWindow(r) {
        $('.win').remove();
        if (r != undefined && $.isFunction(closeCallBack)) {
            closeCallBack(r);
        }
    }

    // 打开窗口
    window.openWindow = function (width, height, title, url) {
        closeWindow();
        var html = '<div class="win"><div class="mask-layer" onclick="closeWindow();"></div><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="title"><h3></h3></div><a href="javascript:void(0)" onclick="closeWindow();" class="close-btn" title="关闭">×</a><iframe class="body-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" src=""></iframe></div></div>';
        var jq = $(html);
        jq.find(".window-panel").height(height).width(width).css("margin-left", -width / 2).css("margin-top", -height / 2);
        jq.find(".title").find(":header").html(title);
        jq.find(".body-panel").height(height - 36).attr("src", url);
        jq.appendTo('body').fadeIn();
        $(".win .window-panel").focus();
    }

    // 提示框
    window.messageBox = function (title, message, callBack) {
        closeWindow();
        closeCallBack = callBack;

        var height = 160, width = 300;
        var html = '<div class="win"><div class="mask-layer"></div><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="title"><h3></h3></div><a href="javascript:void(0)" onclick="closeWindow(false);" class="close-btn" title="关闭">×</a><div class="body-panel"><p class="content"></p><p class="btns"><button class="w-btn" tabindex="1" onclick="closeWindow(true);">确定</button><button class="w-btn" onclick="closeWindow(false);">取消</button></p></div></div></div>';
        var jq = $(html);

        jq.find(".window-panel").height(height).width(width).css("margin-left", -width / 2).css("margin-top", -height / 2);
        jq.find(".title-panel").height(height);
        jq.find(".title").find(":header").html(title);
        jq.find(".body-panel").height(height - 36);
        jq.find(".content").html(message);
        if ($.isFunction(callBack) == false) {
            jq.find(".w-btn:last").remove();
        }
        jq.appendTo('body').fadeIn();
        $(".win .w-btn:first").focus();
    }
})();
